//
//  PickPicture.m
//  iOS_Aotemai
//
//  Created by mac on 2017/9/25.
//  Copyright © 2017年 罗弟祥. All rights reserved.
//

#import "PickPicture.h"

@implementation PickPicture

//选择图片
+(void)getPickPictureWithViewControll:(UIViewController *)vc{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    
    UIAlertAction *action = [UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        //拍照
        [self takePhoto:vc];
    }];
    UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"从相机选择" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        //选择图片
        [self LocalPhoto:vc];
    }];
    UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    [alert addAction:action];
    [alert addAction:action1];
    [alert addAction:action2];
    [vc presentViewController:alert animated:YES completion:nil];
}


//从相册选择
+(void)LocalPhoto:(UIViewController *)vc{
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    //资源类型为图片库
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    picker.delegate = (id)vc;
    //设置选择后的图片可被编辑
        picker.allowsEditing = YES;
    //    [self presentModalViewController:picker animated:YES];
    [vc presentViewController:picker animated:YES completion:nil];
    
    //    [self launchController];
    
}
//拍照
+(void)takePhoto:(UIViewController *)vc{
    //资源类型为照相机
    UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;
    //判断是否有相机
    if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]){
        UIImagePickerController *picker = [[UIImagePickerController alloc] init];
        picker.delegate = (id)vc;
        //设置拍照后的图片可被编辑
        picker.allowsEditing = YES;
        //资源类型为照相机
        picker.sourceType = sourceType;
        [vc presentViewController:picker animated:YES completion:nil];
        
    }else {
        // NSLog(@"该设备无摄像头");
    }
}




@end
